package br.ufal.tci.nexos.arcolive.service.broker.command;

import br.ufal.tci.nexos.arcolive.ArCoLIVEServiceManager;
import br.ufal.tci.nexos.arcolive.command.ArCoLIVEClientCommand;
import br.ufal.tci.nexos.arcolive.command.ArCoLIVECommandResult;
import br.ufal.tci.nexos.arcolive.descriptors.ParticipantDescriptor;
import br.ufal.tci.nexos.arcolive.service.connection.ConnectionRequest;

public class GetParticipantListOfServiceInstanceCommand extends ArCoLIVEClientCommand {
	
	public GetParticipantListOfServiceInstanceCommand(ConnectionRequest request) {
		super(request);
	}
	
	public ArCoLIVECommandResult executeImpl() {
		int serviceId = this.request.getIntegerParameter("serviceId").intValue();
		int instanceId = this.request.getIntegerParameter("instanceId").intValue();
		String response = "";	
		
		ParticipantDescriptor participantDescriptors[] = ArCoLIVEServiceManager.getInstance().getParticipantDescriptors(serviceId, instanceId);
		
		for (int i = 0; i < participantDescriptors.length; i++) {
			response = response + participantDescriptors[i].getParticipantId() + "%" + participantDescriptors[i].getParticipantName() + ",";
		}

		if (response.length() > 0) {
			response = response.substring(0, response.length()-1);
		}
			
		return new ArCoLIVECommandResult(this, response);
	}

}